//Accepted
#include <cstdio>

int  x, y, a, i, sum;
char tmp[20];

int main(){
	//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);
	
	while(scanf("%d %d", &x, &y)==2 && x){
		sum=0;
		for(i=0;i<x;++i){
			scanf("%s %d", tmp, &a);
			sum+=a;
		}
		printf("%d\n",  y*3-sum);
	}
	return 0;
}
